/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function short_url_clear(){
    var short_url = $("#short_url").val();
    if(short_url == '输入需要缩短的网址'){
        $("#short_url").val('');
    }
}

function html_tr(u22, sina, tencent, url,k,total_pv,total_ip,v){
    var str= "";
    var sina_new    = sina.toLowerCase();
//    var top = $("#list_first").html();
//    top     = "<tr id='list_first'>"+top +"</tr>";
//    $("#list_first").remove();
//    var last    = $("#list_url > tbody").html();
    str +='<tr>';
    str +='<td><span id="'+sina_new+k+'">'+v.share+' / '+v.comment+'</span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:flush_count(\''+sina+k+'\','+k+');">刷新</a></td>';
    str +='<td><input id="copy_'+u22+k+'" type="hidden" value="http://u22.cc/'+u22+'"/>http://u22.cc/'+u22+'<span class="copy"><a href="#" id="copy_button_'+u22+k+'">复制</a></span></td>';
    str += sina_url(sina,k);
    str +='<td><a href="http://u22.cc/'+u22+'+">'+u22+'</a></td>';
    str +='<td>'+url+'</td>';
    str +='</tr>';
    return str;
    //copy_short(u22, sina, tencent);
}

function sina_url(sina,k) {
    if(sina == ''){
        return "<a href='javascript:html_sina(\""+sina+"\");'>生成</a>";
    }else{
        var sina_lower    = sina.toLowerCase();
        return '<td><input id="sina_copy_'+sina_lower+k+'" type="hidden" value="http://t.cn/'+sina+'"/>http://t.cn/'+sina+'<span class="copy"><a href="#" id="sina_copy_button_'+sina_lower+k+'">复制</a></span></td>';
    }
}

function flush_count(url,k){
    $.ajax({
       url: sina_action+'flush_weibo_count/url/'+url,
       dataType:"json",
        type:"GET",
        success:function(re){
            if(re.code == 'ok'){
                $("#"+url+k).html(re.share + ' / '+re.comment);
                update_count(url, re.share ,re.comment);
                alert('刷新成功!');
            }else{
                alert(re.msg);
            }
        }
    });
}

//更新评论和分享数
function update_count(url, share_counts, comment_counts){
    $.ajax({
       url: sina_action+'update_weibo_count/url/'+url+'/share_counts/'+share_counts+'/comment_counts/'+comment_counts+'.mk',
       dataType:"json",
        type:"GET",
        success:function(re){
        }
    });
}

function set_copy(data){
        $.each(data, function(k1,v1){
        var clip_sina,clip_tencent,u22,news;
        
        //复制新浪
        if(v1.sina_url !='') {
            var urls    = v1.sina_url.toLowerCase();
            clip_sina = new ZeroClipboard.Client();
            clip_sina.setHandCursor( true );
            clip_sina.setText( $('#sina_copy_'+urls+k1).val());
            clip_sina.glue( 'sina_copy_button_'+urls+k1);
            
            //clip_sina.reposition();
            clip_sina.addEventListener( "complete", function(){
                alert("复制成功！");
            });
        }
        //复制短连接
        u22 = new ZeroClipboard.Client();
        u22.setHandCursor( true );
        u22.setText( $('#copy_'+v1.uhash+k1).val());
        u22.glue( 'copy_button_'+v1.uhash+k1);

        u22.addEventListener( "complete", function(){
            alert("复制成功！");
        });
            
//            news = new ZeroClipboard.Client();
//            news.setHandCursor( true );
//            news.setText( $('#copy_'+v1.tencent_url+k1).val());
//            news.glue( 'copy_button_'+v1.tencent_url+k1);
//            news.addEventListener( "complete", function(){
//                alert("复制成功！");
//            });
    });
}

function copy_short(u22, sina, tencent) {
    var cp1,cp2,cp3;
    cp1 = new ZeroClipboard.Client();
    cp1.setHandCursor( true );
    cp1.setText( $('#copy_'+u22).val());
    cp1.glue( 'copy_button_'+u22);
    cp1.reposition();

    cp2 = new ZeroClipboard.Client();
    cp2.setHandCursor( true );
    cp2.setText( $('#copy_'+sina).val());
    cp2.glue( 'copy_button_'+sina);
    cp2.reposition();
}

